package modeller.databasedesignmodel.relation.index;

import modeller.databasedesignmodel.Attribute;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Jason Ye
 * Date: 21/01/2012
 * Time: 16:20
 */
public abstract class AbstractTableIndex implements ITableIndex, Serializable {

    LinkedList<Attribute> m_attributeList;

    public AbstractTableIndex() {
        m_attributeList = new LinkedList<Attribute>();
    }

    @Override
    public int getIndexEntrySize() {
        int sum = 0;
        for (Attribute col : m_attributeList) {
            sum += col.getAttributeSize();
        }
        return sum;
    }

    @Override
    public List<Attribute> getAttributeList() {
        return m_attributeList;
    }

    @Override
    public void setAttributeList(LinkedList<Attribute> m_structure) {
        this.m_attributeList = m_structure;
    }

    @Override
    public String toString() {
        StringBuffer buf = new StringBuffer();

        buf.append("TABLE INDEX DEFINED on the following attributes: ");
        for (Attribute a : m_attributeList) {
            buf.append(a.getAttributeName());
        }

        return buf.toString();
    }

    @Override
    public void addAttribute(Attribute attribute) {
        m_attributeList.add(attribute);
    }

    @Override
    public void removeAttribute(Attribute attribute) {
        m_attributeList.remove(attribute);
    }
}
